local items = {
	settingsfile = "335惩戒骑.json",
	callback = GUICallback,
	{ type = "title", text = "335惩戒骑 |c0000CED1 糊涂虫" },
	{ type = "separator" },	

	{ type = "page", number = 1, text = "|cffFFFF00保命功能|r" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(1038))..":26:26\124t  拯救之手", tooltip = "拯救之手", enabled = true, key = "HandofSalvation" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(642))..":26:26\124t  圣盾术 HP% <", tooltip = "圣盾术 < HP%", enabled = true, value = 20, key = "DivineShield" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(48788))..":26:26\124t  圣疗术 HP% <", tooltip = "圣疗术 < HP%", enabled = true, value = 10, key = "LayonHands" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(10278))..":26:26\124t  保护之手 HP% <", tooltip = "保护之手 < HP%", enabled = false, value = 20, key = "HandofProtection" },
	{ type = "entry", text = "\124T"..GetItemIcon(36894)..":26:26\124t 使用 治疗石 HP% <", tooltip = "治疗石", enabled = true, value = 30, key = "FelHealthstone" },

	{ type = "page", number = 2, text = "|cFF00FF00输出循环|r" },
	{ type = "separator" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(62124))..":26:26\124t  清算之手 <", tooltip = "使用清算之手进行输出（需要装备相应的雕文）", enabled = false, key = "HandofReckoning" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(62124))..":26:26\124t  智能优先AOE 怪物数量>", tooltip = "智能优先AOE 数量大于>", enabled = true, value= "3", key = "AoeCount" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(53408))..":26:26\124t  智慧审判 <", tooltip = "释放智慧审判回蓝，蓝量 <", enabled = true, value = "50", key = "JudgementofWisdom" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(48819))..":26:26\124t  智能奉献 怪物数量 >", tooltip = "数量大于且奉献CD好了就用", enabled = true, value = 3, key = "Consecration" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(48801))..":26:26\124t  输出循环", tooltip = "开启一键输出模式", enabled = true, key = "Dps" },
	{ type = "page", number = 3, text = "|cFF00FF00防护功能|r" },
	{ type = "separator" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(53601))..":26:26\124t  自动护盾", tooltip = "圣洁护盾", enabled = true, key = "SacredShield" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(64205))..":26:26\124t  神圣牺牲", tooltip = "CD好了就用神圣牺牲", enabled = false, key = "DivineSacrifice" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(31821))..":26:26\124t  光环掌握", tooltip = "CD好了就用光环掌握", enabled = false, key = "AuraMastery" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(1044))..":26:26\124t  焦点自由", tooltip = "对焦点目标使用自由之手", enabled = false, key = "focusAuraMastery" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(48788))..":26:26\124t  焦点圣疗 焦点血量% <", tooltip = "对焦点目标使用圣疗术", enabled = true, value = 35, key = "focusLayonHands" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(10278))..":26:26\124t  焦点保护 焦点血量% <", tooltip = "对焦点目标使用保护之手", enabled = true, value = 35, key = "focusHandofProtection" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(6940))..":26:26\124t  焦点牺牲 焦点血量% <", tooltip = "对焦点目标使用牺牲之手", enabled = true, value = 35, key = "focusHandofSacrifice" },
	{ type = "page", number = 4, text = "|cFF00FF00辅助功能|r" },
	{ type = "separator" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(10308))..":26:26\124t  制裁之锤", tooltip = "制裁之锤打断", enabled = false, key = "HammerofJustice" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(20066))..":26:26\124t  忏悔", tooltip = "忏悔打断", enabled = false, key = "Repentance" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(4987))..":26:26\124t   清洁术", tooltip = "清洁术驱散", enabled = false, key = "Cleanse" },	
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(1044))..":26:26\124t   自由之手", tooltip = "自由之手", enabled = false, key = "HandofFreedom" },	
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(19746))..":26:26\124t  自动光环", tooltip = "自动光环", enabled = true, key = "AutoAura" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(48932))..":26:26\124t  力量祝福", tooltip = "力量祝福", enabled = true, key = "BlessingofMight" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(20060))..":26:26\124t  自动目标", tooltip = "自动目标", enabled = true, key = "AutoTarget" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(28730))..":26:26\124t  奥术洪流 MP% <", tooltip = "奥术洪流（血精灵专用）", enabled = true, value = 95, key = "ArcaneTorrent" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(54428))..":26:26\124t  神圣恳求 MP% <", tooltip = "神圣恳求", enabled = true, value = 75, key = "DivinePlea" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(20375))..":26:26\124t  自动圣印", tooltip = "自动圣印", enabled = true, value = 2, key = "Seal" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(51306))..":26:26\124t  调试", tooltip = "显示调试信息", enabled = false, key = "debug" },
	
};


 
local function GetSetting(name)
    for k, v in ipairs(items) do
        if v.type == "entry"
         and v.key ~= nil
         and v.key == name then
            return v.value, v.enabled
        end
    end
end;

local itemTable = {}

local function loadSetting()
	for k, v in ipairs(items) do
		if v.type == "entry" and v.key ~= nil then
				
		end
  end
end



local function OnLoad()

	ni.GUI.AddFrame("335惩戒骑", items);
end;

local function OnUnLoad()  
	ni.GUI.DestroyFrame("335惩戒骑");
end;

local freedomdebuff = {69649, 45524, 1715, 3408, 59638, 20164, 25809, 31589, 51585, 50040, 50041, 31124, 122, 44614, 339, 45334, 58179, 61391, 19306, 19185, 35101, 5116, 2974, 61394, 54644, 50245, 50271, 54706, 4167, 33395, 55080, 6136, 120, 116, 31589, 20170, 31125, 3409, 26679, 64695, 63685, 8056, 8034, 18118, 18223, 63311, 23694, 1715, 12323, 39965, 55536, 13099, 32859, 32065, 22800, 3604, 33967, 12023, 47698, 38316, 15063, 49717 }
;

local spells = {
	DivineShield = {id = 642, name = GetSpellInfo(642), tooltip = ""},  --圣盾术
	DivineProtection = {id = 498, name = GetSpellInfo(498), tooltip = ""},  --圣佑术
	LayonHands = {id = 48788, name = GetSpellInfo(48788), tooltip = ""},  --圣疗术
	Cleanse = {id = 4987, name = GetSpellInfo(4987), tooltip = ""},  --清洁术
	Exorcism = {id = 48801, name = GetSpellInfo(48801), tooltip = ""},  --驱邪术
	CrusaderStrike = {id = 35395, name = GetSpellInfo(35395), tooltip = ""},  --十字军打击
	DivineFavor = {id = 20216, name = GetSpellInfo(20216), tooltip = ""},  --神恩术
	HandofProtection = {id = 10278, name = GetSpellInfo(10278), tooltip = ""},  --保护之手
	HandofSalvation = {id = 1038, name = GetSpellInfo(1038), tooltip = ""},  --拯救之手
	HandofFreedom = {id = 1044, name = GetSpellInfo(1044), tooltip = ""},  --自由之手
	HandofReckoning = {id = 62124, name = GetSpellInfo(62124), tooltip = ""},  --清算之手
	HandofSacrifice = {id = 6940, name = GetSpellInfo(6940), tooltip = ""},  --牺牲之手
	HammerofJustice = {id = 10308, name = GetSpellInfo(10308), tooltip = ""},  --制裁之锤
	HammerofWrath = {id = 48806, name = GetSpellInfo(48806), tooltip = ""},  --愤怒之锤
	Repentance = {id = 20066, name = GetSpellInfo(20066), tooltip = ""},  --忏悔
	JudgementofLight = {id = 20271, name = GetSpellInfo(20271), tooltip = ""},  --圣光审判
	JudgementofWisdom = {id = 53408, name = GetSpellInfo(53408), tooltip = ""},  --智慧审判
	JudgementofJustice = {id = 53407, name = GetSpellInfo(53407), tooltip = ""},  --公正审判
	SealofCorruption = {id = 53736, name = GetSpellInfo(53736), tooltip = "腐蚀圣印"},  --腐蚀圣印
	SealofVengeance = {id = 31801, name = GetSpellInfo(31801), tooltip = "复仇圣印"},  --复仇圣印
	SealofLight = {id = 20165, name = GetSpellInfo(20165), tooltip = ""},  --光明圣印
	SealofCommand = {id = 20375, name = GetSpellInfo(20375), tooltip = ""},  --命令圣印
	SealofWisdom = {id = 20166, name = GetSpellInfo(20166), tooltip = ""},  --智慧圣印
	SealofRighteousness = {id = 21084, name = GetSpellInfo(21084), tooltip = ""},  --正义圣印
	SealofJustice = {id = 20164, name = GetSpellInfo(20164), tooltip = ""},  --公正圣印
	CrusaderAura = {id = 32223, name = GetSpellInfo(32223), tooltip = ""},  --十字军光环
	RetributionAura = {id = 54043, name = GetSpellInfo(54043), tooltip = "惩戒光环"},  --惩戒光环
	FrostResistanceAura = {id = 48945, name = GetSpellInfo(48945), tooltip = ""},  --冰霜抗性光环
	ShadowResistanceAura = {id = 48943, name = GetSpellInfo(48943), tooltip = ""},  --暗影抗性光环
	FireResistanceAura = {id = 48947, name = GetSpellInfo(48947), tooltip = ""},  --火焰抗性光环
	ConcentrationAura = {id = 19746, name = GetSpellInfo(19746), tooltip = ""},  --专注光环
	DevotionAura = {id = 48942, name = GetSpellInfo(48942), tooltip = ""},  --虔诚光环 
	AuraMastery = {id = 31821, name = GetSpellInfo(31821), tooltip = ""},  --光环掌握
	GreaterBlessingofWisdom = {id = 48938, name = GetSpellInfo(48938), tooltip = ""},  --强效智慧祝福	
	GreaterBlessingofKings = {id = 25898, name = GetSpellInfo(25898), tooltip = ""},  --强效王者祝福	
	GreaterBlessingofMight = {id = 48934, name = GetSpellInfo(48934), tooltip = ""},  --强效力量祝福
	AvengingWrath = {id = 31884, name = GetSpellInfo(31884), tooltip = ""},  --复仇之怒
	RighteousFury = {id = 25780, name = GetSpellInfo(25780), tooltip = ""},  --正义之怒
	ShieldofRighteousness = {id = 61411, name = GetSpellInfo(61411), tooltip = ""},  --正义盾击
	RighteousDefense = {id = 31789, name = GetSpellInfo(31789), tooltip = ""},  --正义防御
	DivineSacrifice = {id = 64205, name = GetSpellInfo(64205), tooltip = ""},  --神圣牺牲
	DivineIntervention = {id = 19752, name = GetSpellInfo(19752), tooltip = ""},  --神圣干涉
	DivinePlea = {id = 54428, name = GetSpellInfo(54428), tooltip = ""},  --神圣恳求
	HolyWrath = {id = 48817, name = GetSpellInfo(48817), tooltip = ""},  --神圣愤怒
	HolyShock = {id = 48825, name = GetSpellInfo(48825), tooltip = ""},  --神圣震击
	DivineIllumination = {id = 31842, name = GetSpellInfo(31842), tooltip = ""},  --神启
	Consecration = {id = 48819, name = GetSpellInfo(48819), tooltip = ""},  --奉献
	BlessingofWisdom = {id = 48936, name = GetSpellInfo(48936), tooltip = ""},  --智慧祝福	
	BlessingofKings = {id = 20217, name = GetSpellInfo(20217), tooltip = ""},  --王者祝福	
	BlessingofMight = {id = 48932, name = GetSpellInfo(48932), tooltip = ""},  --力量祝福
	HolyLight = {id = 48782, name = GetSpellInfo(48782), tooltip = ""},  --圣光术
	DivineStorm = {id = 53385, name = GetSpellInfo(53385), tooltip = ""},  --神圣风暴
	BeaconofLight = {id = 53563, name = GetSpellInfo(53563), tooltip = ""},  --圣光道标
	FlashofLight = {id = 48785, name = GetSpellInfo(48785), tooltip = ""},  --圣光闪现
	SacredShield = {id = 53601, name = GetSpellInfo(53601), tooltip = ""},  --圣洁护盾
	ArcaneTorrent = {id = 28730, name = GetSpellInfo(28730), tooltip = ""},  --奥术洪流
	FelHealthstone = {id = 36894, name = GetItemInfo(36894), tooltip = ""}, --治疗石
	ArtOfWar = {id = 12312, name = GetItemInfo(123), tooltip = ""},
};

 
local Cache = {
	enemies = ni.player.enemiesinrange(35),
   
}

local queue = {
	"Cache",
	"Pause",
	"Fel Healthstone",
	"DivineShield",
	"HandofSalvation",
    "HammerofJustice",
	"Repentance",
	"Cleanse",
	"HandofFreedom",
	"AutoTarget",
	"Seal",
	"AutoAura",
	"BlessingofMight",
	"JudgementofWisdom",
	"Consecration",
	"DivineStorm",
	"HammerofWrath",
	"CrusaderStrike",
	"DivineStormA",
	"Exorcism",
	"ConsecrationA",
	"SacredShield",
	"DivineIllumination",
	"DivinePlea",
	"DivineSacrifice",
	"AuraMastery",
	"ArcaneTorrent",
	"debug",
	
};

local delaytime = 0

local function UnitCastSpellTime(unit) 
	unit = unit or target
	if not ni.unit.exists(unit) then
		return -1,-1,"";
	end
	local spell, _, _, _, startTime, endTime = UnitCastingInfo(unit)
	print(spell)
	if spell then 
		local finish = endTime/1000 - GetTime()
		return tonumber(format("%.2f",finish) ),tonumber(format("%.2f",(endTime -startTime) /1000)),spell
	end
	local spellch, _, _, _, startTime, endTimech = UnitChannelInfo(unit)
	if spellch then 
		local finishch = endTimech/1000 - GetTime()
		return tonumber(format("%.2f",finishch) ),tonumber(format("%.2f",(endTimech -startTime) /1000)),spellch
	end
	return -1,-1,"";
end

local function StringFind(String,Tbl,Type) 
	if (not String) or (not Tbl) then
		return nil;
	end
	if type(Tbl) == "string" then
	
		Tbl = { strsplit(",",Tbl) }
	elseif type(Tbl) == "table" then
	else
		return nil;
	end
	if type(String) == "string" then	
		String = { strsplit(",",String) }
	elseif type(String) == "table" then
	else
		return nil;
	end
	if Type == nil then
		Type=0
	end
	local n;
	local Tbl_index=1;
	local String_index=1;
	for i,v in ipairs(Tbl) do
		String_index=1;
		for k,va in ipairs(String) do
			n = strfind(va,v,1,true);
			if not n then
				n = strfind(strlower(va),strlower(v),1,true);
			end			
				if n then
					if Type == -1 then
						return n,v,va,Tbl_index,String_index;						
					elseif Type == 0  then
						if va == v then
							return n,v,va,Tbl_index,String_index;
						end					
					elseif Type == n then
						return n,v,va,Tbl_index,String_index;
					end
				end
			String_index=String_index+1;
		end		
		Tbl_index=Tbl_index+1;
	end
	return nil;
end

 local function dmbzl(unit)
		     local unit = unit or "target"
             if ni.unit.buff(unit, spells.BeaconofLight.id, "player") then return nil end  
			 if ni.player.ismoving() and ni.spell.cd(spells.HolyShock.id) <1
		     then ni.spell.cast(spells.HolyShock.name, unit) return true
             else ni.spell.cast(spells.HolyLight.name, unit) return true
             end   
           end

 local function ValidUsable(id, tar)
	if ni.spell.available(id) and ni.spell.valid(tar, id, true, true) then
		return true
	end
	return false
 end

 local function Ddmb(tar)
   if ni.unit.iscasting(tar) or ni.unit.ischanneling(tar) then
        return true end
	return false
 end


local abilities = {
	["Pause"] = function()     --停止条件
		if ni.tnr.pause() then
			return true
		end

		-- 移除自己的神圣牺牲
		if ni.unit.buff("player", spells.DivineSacrifice.id, "player") then
			ni.player.cancelbuff(spells.DivineSacrifice.id)
		end

		-- 神圣干涉，不需要动作
		if ni.unit.buff("player", spells.DivineIntervention.id) then 
			return true
		end

		
		
	end,

	["Cache"] = function()
	        Zhandou = UnitAffectingCombat("player") or UnitAffectingCombat("target") or false
			Cache.enemies = ni.player.enemiesinrange(35)
			Cache.enemieu = ni.player.enemiesinrange(7)
			tgzlmb = ""  if UnitCanAttack("player", "target") then tgzlmb = "targettarget" else  tgzlmb = "target" end
		    mainTank, offTank = ni.tanks()
		    QshengqishiyuduQ = QshengqishiyuduQ or CreateFrame("frame","QshengqishiyuduQ")      
            QshengqishiyuduQ:RegisterEvent("UNIT_SPELLCAST_SENT")     
            QshengqishiyuduQ:SetScript("OnEvent", function(_,_,a,b,_,c)     
            if a=="player" then
                if b=="圣光道标" then 
				dbmb=c
				print("道标已补》》》》》》"..c)
				end
                if b=="圣光术" then
				zlmb=c
				print("正在为》》》"..c.."《《《预读大圣光")
				end      
                if b=="圣洁护盾" then 
				hdmb=c
				print("圣洁护盾》》》》》》"..c)
				end 
                QshengqishiyuduQ:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")  end  end)   
		end,

	["AutoTarget"] = function()    --自动目标
	local _, enabled = GetSetting("AutoTarget")
		if enabled then
		  if UnitAffectingCombat("player") 
		    and not ni.unit.exists("target")  then
			ni.player.runtext("/startattack")
			return true
		  end
		end
	end,

	["AutoAura"] = function()    --自动光环
	local _, enabled = GetSetting("AutoAura")
	  if enabled then
		if IsMounted() or ni.player.debuffs("71941||70873") then
		   if not ni.player.aura(spells.CrusaderAura.id) then ni.spell.cast(spells.CrusaderAura.name) return true end
	    elseif not ni.player.buffs("54043||48945||48943||48947||19746||48942")  then
		   ni.spell.cast(spells.RetributionAura.name) return true 
		end
	  end
	end,

	

	["BlessingofMight"] = function()    --力量祝福
	local _, enabled = GetSetting("BlessingofMight")
	  if enabled then
		if not ni.player.buffs("48932||48934")  then
		   ni.spell.cast(spells.BlessingofMight.name,"player") return true 
		end
	  end
	end,

	["DivineShield"] = function()  --圣盾术
	local value, enabled = GetSetting("DivineShield")
		if enabled then
		   if UnitAffectingCombat("player")
			and not ni.player.debuff(25771)
			and  ni.spell.available(spells.DivineShield.id)
			and ni.player.hp() <= value then
				ni.spell.cast(spells.DivineShield.name)
				return true; end
		end 
	end,

	["LayonHands"] = function()  --圣疗术
	local value, enabled = GetSetting("LayonHands")
		if enabled  then
		   if UnitAffectingCombat("player")
			and not ni.player.debuff(25771)
			and ni.spell.available(spells.LayonHands.id)
			and ni.player.hp() <= value then
				ni.spell.cast(spells.LayonHands.name,"player")
				return true; end
		end 
	end,

	["HandofProtection"] = function()  --保护之手
	local value, enabled = GetSetting("HandofProtection")
		if enabled then
		   if ni.player.hp() <= value
		    and UnitAffectingCombat("player")
			and not ni.player.debuff(25771)
			and ValidUsable(spells.HandofProtection.id,"player") <1
		    then
				ni.spell.cast(spells.HandofProtection.name,"player")
				return true; end
		end 
	end,

	["AuraMastery"] = function()  --自动光环掌握
	local _, enabled = GetSetting("AuraMastery")
		if enabled then
		if Zhandou 
			and  ni.spell.available(spells.AuraMastery.id)
			then
				ni.spell.cast(spells.AuraMastery.name)
				return true; end
		end 
	end,
	
	["DivinePlea"] = function()  --神圣恳求
	local value, enabled = GetSetting("DivinePlea")
		if enabled then
		   if ni.player.power() <= value
			and  ni.spell.available(spells.DivinePlea.id)
		    then
				ni.spell.cast(spells.DivinePlea.name,"player")
				return true; end
		end 
	end,

	["HandofSalvation"] = function()  --拯救之手
	local _, enabled = GetSetting("HandofSalvation")
		if enabled then
		    if ni.player.threat() >= 2
		     and  ni.spell.available(spells.HandofSalvation.id)
			 then
				ni.spell.cast(spells.HandofSalvation.name, "player")
				return true; end
		end
	end,

	["Cleanse"] = function()	  --清洁术
	local _, enabled = GetSetting("Cleanse")
        if enabled then
		  for i = 1, #ni.members do
               local ally = ni.members[i].unit
               if ni.unit.debufftype(ally,"Magic|Disease|Poison")
			      and ni.spell.available(spells.Cleanse.id)  
			      and ni.spell.valid(ally, spells.Cleanse.id, false, true, true)
			   then
			   ni.spell.cast(spells.Cleanse.name, ally)  return true
               end
		   end
        end
    end,

	 ["HandofFreedom"] = function()   --自由之手
	 local _, enabled = GetSetting("HandofFreedom")
        if enabled then
            for _, x in ipairs(freedomdebuff) do
                for i = 1, #ni.members do
                    local Ally = ni.members[i].unit
                    if ni.unit.debuff(Ally, x)
					and ni.spell.available(spells.HandofFreedom.id) 
                    and ni.spell.valid(Ally, spells.HandofFreedom.id, false, true, true)
                     then
                        ni.spell.cast(spells.HandofFreedom.name, Ally)
                        return true; end
                end
            end
        end
    end,

	["Fel Healthstone"] = function()  --治疗石
	local value, enabled = GetSetting("FelHealthstone")
		if enabled  then
			if UnitAffectingCombat("player")
			and ni.player.hp() <= value
			and ni.player.itemready(spells.FelHealthstone.id)  then
				ni.player.useitem(spells.FelHealthstone.name)
				return true; end
		end
	end,

	["HammerofJustice"] = function()   --自动制裁
	local _, enabled = GetSetting("HammerofJustice")
		if enabled  then
			for i = 1, #Cache.enemies do
				local target = Cache.enemies[i].guid
				local x, y, z, facing, unittype, targett, height = ni.unit.info(target)
				if  ni.unit.exists(targett) 
						and Ddmb(target)
						and ValidUsable(spells.HammerofJustice.id,target)
				then
					ni.spell.cast(spells.HammerofJustice.name, target)
					return true
				end
			end
		end
	end,

	["Repentance"] = function()   --自动忏悔
	local _, enabled = GetSetting("Repentance")
		if enabled  then
			for i = 1, #Cache.enemies do
				local target = Cache.enemies[i].guid
				local x, y, z, facing, unittype, targett, height = ni.unit.info(target)
				if  ni.unit.exists(targett)
						and Ddmb(target)
						and ValidUsable(spells.Repentance.id,target)
				then
					ni.spell.cast(spells.Repentance.name, target)
					return true
				end
			end
		end
	end,

	["Seal"] = function()  --自动圣印
	local value, enabled = GetSetting("Seal")
	local enear = #ni.player.enemiesinrange(15)
        if enabled and ni.player.power()>30  then
		   if ni.unit.isboss("target") then 
		    if not ni.player.buffs("53736||31801") then
		      ni.spell.cast(spells.SealofCorruption.name) return true 
		     end
		   elseif enear > value  then
		     if not ni.player.buff(20375) then
		      ni.spell.cast(spells.SealofCommand.name) return true 
		     end
		   end
		end
	end,

	["focusHandofFreedom"] = function()  --焦点自由
	local _, enabled = GetSetting("focusHandofFreedom")
        if enabled 
		and  ValidUsable(spells.HandofFreedom.id,"focus")
		then
		    ni.spell.cast(spells.HandofFreedom.name,"focus") return true
		   
		end
	end,

	["focusHandofSacrifice"] = function()  --焦点牺牲
	local value, enabled = GetSetting("fucosHandofSacrifice")
        if enabled 
		and ni.unit.hp("focus") <value
		and ValidUsable(spells.HandofSacrifice.id,"focus")
		then
		    ni.spell.cast(spells.HandofSacrifice.name,"focus") return true
		   
		end
	end,

	["focusLayonHands"] = function()  --焦点圣疗
	local value, enabled = GetSetting("focusLayonHands")
        if enabled 
		and ni.unit.hp("focus") <value
		and not ni.unit.buff("focus",25771)
		and ValidUsable(spells.LayonHands.id,"focus")
		then
		    ni.spell.cast(spells.LayonHands.name,"focus") return true
		end
	end,

	["focusHandofProtection"] = function()  --焦点保护
	local value, enabled = GetSetting("focusHandofProtection")
        if enabled 
		and ni.unit.hp("focus") <value
		and not ni.unit.buff("focus",25771)
		and ValidUsable(spells.HandofProtection,"focus")
		then
		    ni.spell.cast(spells.HandofProtection.name,"focus") return true  
		end
	end,

	["JudgementofWisdom"] = function()  --智慧审判
	local _, enabled = GetSetting("JudgementofWisdom")
        if enabled then
		if Zhandou 
		and ValidUsable(spells.JudgementofWisdom.id, "target")
		then
		    ni.spell.cast(spells.JudgementofWisdom.name) return true end
		end
	end,

	["Consecration"] = function()  --智能奉献
	local value, enabled = GetSetting("Consecration")
	local enear = #ni.player.enemiesinrange(7) --8码内敌人数量 
	  if enabled then
		 if enear >= value 
		 and Zhandou
		 and not ni.player.ismoving()
		 and ni.player.power()>30
		 and ni.spell.available(spells.Consecration.id) then
		     ni.spell.cast(spells.Consecration.name) 
			return true end
	  end
	end,

	["DivineStorm"] = function()  --神圣风暴
	local value,  enabled = GetSetting("DivineStorm")
	local enear = #ni.player.enemiesinrange(7) --8码内敌人数量 
        if enabled then
		if Zhandou
		and enear>value and 
		ni.spell.available(spells.DivineStorm.name)
		then
		    ni.spell.cast(spells.DivineStorm.name) return true end
		end
	end,

	["HammerofWrath"] = function()   --愤怒之锤
	local _, enabled = GetSetting("HammerofWrath")
		if enabled 
		   then
			for i = 1, #Cache.enemies do
				local target = Cache.enemies[i].guid
				local x, y, z, facing, unittype, targett, height = ni.unit.info(target)
				if  ni.unit.exists(targett)
				 and not UnitIsDeadOrGhost(target)
						and ni.unit.hp(target) <20
						and ValidUsable(spells.HammerofWrath.id,target)
				then
					ni.spell.cast(spells.HammerofWrath.name, target)
					return true
				end
			end
		end
	end,

	["CrusaderStrike"] = function()  --十字军打击
	local _, enabled = GetSetting("CrusaderStrike")
        if enabled and Zhandou
		and ValidUsable(spells.CrusaderStrike.id, "target")
		then
		    ni.spell.cast(spells.CrusaderStrike.name) return true
		end
	end,

	["DivineStormA"] = function()  --神圣风暴
	local value,  enabled = GetSetting("DivineStorm")
	local enear = #ni.player.enemiesinrange(7)
        if enabled then
		if Zhandou 
		and enear>0
		and ni.spell.available(spells.DivineStorm.name)
		then
		    ni.spell.cast(spells.DivineStorm.name) return true end
		end
	end,

	["Exorcism"] = function()  --驱邪术
	local _, enabled = GetSetting("Exorcism")
        if enabled 
		and Zhandou
		and ni.player.buff(59578)
		 and ValidUsable(spells.Exorcism.id, "target")
		then
		    ni.spell.cast(spells.Exorcism.name) return true
		end
	end,

	["ConsecrationA"] = function()  --奉献
	local value, enabled = GetSetting("Consecration")
	local enear = #ni.player.enemiesinrange(7)
	  if enabled then
		 if ni.player.power()>40
		 and not ni.player.ismoving()
		 and Zhandou
		 and enear>0
		 and ni.spell.available(spells.Consecration.id) then
		     ni.spell.cast(spells.Consecration.name) 
			return true end
	  end
	end,

	["SacredShield"] = function()  --自动圣洁护盾
	local _, enabled = GetSetting("SacredShield")
	local hdmb = hdmb or UnitName("focus") or UnitName("player")
	    if enabled 
		and ni.unit.buffremaining(hdmb,spells.SacredShield.id,"player") <3 and
		ni.spell.cast(spells.SacredShield.name,hdmb)
		then
		return true 
		 end 
	end, 

	["debug"] = function()  --调试
	local _, enabled = GetSetting("debug")
		if enabled then
		     ni.vars.debug = true
		else
             ni.vars.debug = false
		end
	end,

	["ArcaneTorrent"] = function()  --奥术洪流
	local value, enabled = GetSetting("ArcaneTorrent")
		if enabled
		    and Zhandou
			and ni.player.power() <= value
			and ni.spell.available(spells.ArcaneTorrent.id) then 
				ni.spell.cast(spells.ArcaneTorrent.name)
				return true;
		end
	end,

	["Dps"] = function()  
		local value, enabled = GetSetting("Dps")
		if enabled and ni.tnr.attack() then
			-- 清算之手功能
			local _, handofReckoning = GetSetting("HandofReckoning")
			if handofReckoning and ni.tnr.valid("target", spells.HandofReckoning.id) then
				ni.spell.cast(spells.HandofReckoning.name)
			end

			-- 优先AOE
			local aoeCount, aoeEnabled = GetSetting("AoeCount")
			local targetCount = ni.unit.enemiesinrange(8)
			if aoeEnabled and targetCount > aoeCount then
				if ni.tnr.valid("target", spells.DivineStorm.id) then
					ni.spell.cast(spells.DivineStorm.name)
					return true
				end
				if ni.tnr.valid("target", spells.Consecration.id) then
					ni.spell.cast(spells.Consecration.name)
					return true
				end
			end

			-- 2T10优先风暴
			if ni.tnr.inventoryitemcount("肩膀") > 1 and ni.tnr.valid("target", spells.DivineStorm.id) then 
				ni.spell.cast(spells.DivineStorm.name)
				return true
			end

			-- 装等高的时候优先审批
			if ni.unit.itemlvl("player") > 250 and ni.tnr.valid("target", spells.JudgementofWisdom.id) then 
				ni.spell.cast(spells.JudgementofWisdom.name)
				return true
			end

			if ni.unit.hp("target") < 20 and ni.tnr.valid("target", spells.HammerofWrath.id) then 
				ni.spell.cast(spells.HammerofWrath.name)
				return true
			end

			-- 审判
			if ni.tnr.valid("target", spells.JudgementofWisdom.id) then 
				if ni.unit.power("player") > 50 then -- 判断蓝量
					ni.spell.cast(spells.JudgementofLight.name)
				else
					ni.spell.cast(spells.JudgementofWisdom.name)
				end
				return true
			end

			-- 十字军打击
			if ni.tnr.valid("target", spells.CrusaderStrike.id) then 
				ni.spell.cast(spells.CrusaderStrike.name)
				return true
			end

			-- 神圣风暴
			if ni.tnr.valid("target", spells.DivineStorm.id) then 
				ni.spell.cast(spells.DivineStorm.name)
				return true
			end

			-- 奉献
			if ni.tnr.valid("target", spells.Consecration.id) then 
				ni.spell.cast(spells.Consecration.name)
				return true
			end

			-- 战争艺术释放驱邪术
			if ni.unit.buff("player", spells.ArtOfWar.id) and ni.tnr.valid("target", spells.Exorcism.id) then 
				ni.spell.cast(spells.Exorcism.name)
				return true
			end
		end
	end,

};
ni.bootstrap.profile("335惩戒骑", queue, abilities, OnLoad, OnUnLoad);	
